package leetcode;

import java.util.ArrayList;
import java.util.List;

public class LeetCode113 {

    List<List<Integer>> result = new ArrayList<>();

    public List<List<Integer>> pathSum(TreeNode root, int sum) {
        if (root == null)
            return result;
        helper(root, sum, new ArrayList<>());
        return result;
    }

    private void helper(TreeNode node, int sum, List<Integer> list) {
        List<Integer> tmpList = new ArrayList<>(list);
        tmpList.add(node.val);
        int num = sum - node.val;
        if (node.left == null && node.right == null && num == 0) {
            result.add(tmpList);
        } else {
            if (node.left != null)
                helper(node.left, num, tmpList);
            if (node.right != null)
                helper(node.right, num, tmpList);
        }
    }
//------------------------------------------------------------------
}
